local kunzhan = fk.CreateSkill{
    name = "ym1__kunzhan",
    tags = { Skill.Switch },
    dynamic_desc = function (self, player, lang)
        local str = "转换技，你使用/被使用基本或单体伤害牌时："
        if player:getSwitchSkillState("ym1__kunzhan") == fk.SwitchYang then
            str = str .. "<font color='#6fb8cc'>①将“滅忤”中的一项改为此牌名（不能选择上次的修改项）；</font>②检索并获得上次修改掉的牌名。"
        else
            str = str .. "①将“滅忤”中的一项改为此牌名（不能选择上次的修改项）；<font color='#6fb8cc'>②检索并获得上次修改掉的牌名。</font>"
        end
        return str
    end,
}
Fk:loadTranslationTable{
    ["ym1__kunzhan"] = "困战",
    [":ym1__kunzhan"] = "转换技，你使用/被使用基本或单体伤害牌时："..
    "①将“滅忤”中的一项改为此牌名（不能选择上次的修改项）；"..
    "②检索并获得上次修改掉的牌名。",
    ["#ym1__kunzhan"] = "困战：将“滅忤”中的一项改为%arg",
    ["@ym1__kunzhan"] = "困战",
}
kunzhan:addEffect(fk.CardUsing,{
    anim_type = "switch",
    can_trigger = function(self, event, target, player, data)
        if (target == player or (data.tos and table.contains(data.tos, player))) and player:hasSkill(self) then
            return data.card.type == Card.TypeBasic or (not data.card.multiple_targets and data.card.is_damage_card)
        end
    end,
    on_cost = Util.TrueFunc,
    on_use = function (self, event, target, player, data)
        local room = player.room
        if player:getSwitchSkillState(kunzhan.name, true) == fk.SwitchYang then
            local name = data.card.trueName
            local all_choices = type(player:getMark("ym1__miewu")) == "table" and player:getMark("ym1__miewu") or {"slash","duel"}
            local choices = type(player:getMark("ym1__miewu")) == "table" and player:getMark("ym1__miewu") or {"slash","duel"}
            if player:getMark("ym1__kunzhan") > 0 then
                table.removeOne(choices,all_choices[player:getMark("ym1__kunzhan")])
            end
            local result = room:askToChoice(player,{
                choices = choices,
                skill_name = kunzhan.name,
                prompt = "#ym1__kunzhan:::"..name
            })
            room:setPlayerMark(player,"ym1__kunzhan-before",result)
            if #choices > 1 then
                if result == all_choices[2] then
                    room:setPlayerMark(player,"ym1__kunzhan",1)
                end
            end
            room:addPlayerMark(player,"ym1__kunzhan",1)
            if player:getMark("ym1__kunzhan") > 2 then room:setPlayerMark(player,"ym1__kunzhan",1) end
            --room:setPlayerMark(player,"ym1__kunzhan-after",name)
            room:setPlayerMark(player,"@ym1__kunzhan",Util.TranslateMapper(result) .. "→<font color='#6fb8cc'>" .. Util.TranslateMapper(name) .. "</font>")
            all_choices[player:getMark("ym1__kunzhan")] = name
            room:setPlayerMark(player,"ym1__miewu",all_choices)
            room:setPlayerMark(player,"@ym1__miewu",table.concat(table.map(all_choices, function(element,index)
                local str = Fk:translate(element)
                if index == player:getMark("ym1__kunzhan") then
                    str = "<font color='#6fb8cc'>" .. str .. "</font>"
                end
                return str
            end)," "))
        else
            local name = player:getMark("ym1__kunzhan-before")
            local cards = room:getCardsFromPileByRule(name, 1)
            if #cards == 0 then
                cards = room:getCardsFromPileByRule(name, 1, "discardPile")
            end
            if #cards > 0 then
                room:obtainCard(player, cards[1], true, fk.ReasonJustMove, nil, kunzhan.name)
            end
        end
    end,
})
return kunzhan